<template>
  <div class="home">
    <h1>
      新闻创建页
    </h1>
    <hr>

    <el-form ref="form" :model="newData" label-width="80px">
      <el-form-item label="标题">
        <el-input v-model="newData.title"></el-input>
      </el-form-item>
      <el-form-item label="描述">
        <el-input type="textarea" v-model="newData.desc"></el-input>
      </el-form-item>

      <el-form-item label="详情">
        <quill-editor
          v-model="newData.detail"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>

import axios from 'axios'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'

import { quillEditor } from 'vue-quill-editor'

export default {
  name: 'AdminNewsEdit',
  data() {
    return {
      newData: {},
    }
  },
  components: {
    quillEditor
  },
  methods: {
    async onSubmit() {
      try {
        const res = await axios({
          method: 'POST',
          url: `http://localhost:3000/news`,
          data: this.newData
        })
        this.$router.replace({
          name: 'admin-news',
        })
        this.$notify.success({
          title: '成功',
          message: '创建成功!!!'
        });
      } catch (e) {
        this.$notify.error({
          title: '错误',
          message: '网络错误请刷新重试！'
        });
      }
    },
  }
}
</script>
